package STUDENT.TRANDAODAIVI;

import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;


class bookborrowedtype{
	private String name;
	private int ammount;
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	public int getAmmount() {
		return ammount;
	}
	public void setAmmount(int ammount) {
		this.ammount = ammount;
	}//i=0->x=heo->add heo//i=1->x=ga->add ga//i=2->x=bo->addbo
	//i=3->x=heo..j=0--j=3
}
public class test {

	public static ArrayList<String>management=new ArrayList<String>();
	public static void rankBook(){
		System.out.println("Danh sach sau khi duoc sap xep: ");
		List<bookborrowedtype> danhsach=new ArrayList<bookborrowedtype>();
		bookborrowedtype x;//0.heo- 1.ga- 2.bo- 3.heo- 4.heo- 5.ga
		for (int i=0;i<management.size();i++){
			x=new bookborrowedtype();
			x.setName(management.get(i));
			int zh=0;
			if(i>0){
			labelAll:for (int j=0;j<danhsach.size();j++){
				if(x.getName()==danhsach.get(j).getName()){
				   zh=1;break labelAll;
				}else{zh=0;}
			}
			if(zh==0){danhsach.add(x);};
			}
			
		}
		for	(int i=0;i<management.size();i++){
			for(int j=0;j<danhsach.size();j++){
				if(management.get(i)==danhsach.get(j).getName()){
					danhsach.get(j).setAmmount(danhsach.get(j).getAmmount()+1);
				}
			}
		}
		for (int i=0;i<danhsach.size();i++){
			for(int j=i+1;j<danhsach.size();j++){
				if(danhsach.get(i).getAmmount()<danhsach.get(j).getAmmount()){
					bookborrowedtype a=new bookborrowedtype();
					a=danhsach.get(i);
					danhsach.set(i,danhsach.get(j));
					danhsach.set(j, a);
				}
			}
		}
		for(int i=0;i<danhsach.size();i++){
			System.out.println("Sach: "+danhsach.get(i).getName());
			System.out.println("Co  : "+danhsach.get(i).getAmmount()+" nguoi muon");
			System.out.println("");
		}
		
}	
	public static void main(String[] args) {
	management.add("heo");
	management.add("heo");
	management.add("bo");
	management.add("ga");		
	management.add("ga");
	management.add("bo");
	management.add("heo");
	management.add("heo");
	management.add("ga");
	test.rankBook();
}
}
	

